package demo02;

import java.util.Arrays;
import java.util.Scanner;

/*题目：有n个整数，使其前面各数顺序向后移m个位置，最后m个数变成最前面的m个数*/
public class topic36 {
    public static void main(String[] args) {
        /*有n个整数，使其前面各数顺序向后移m个位置，最后m个数变成最前面的m个数*/
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要移动几个位置:");
        int location = sc.nextInt();
        int[] newArr = new int[location];
        //将要移动的元素放入临时数组
        for (int i = 0; i < newArr.length; i++) {
            newArr[i] = arr[arr.length - location + i];
        }
        //0-(n-m)个元素往后移
        for (int i = arr.length - 1; i >= location; i--) {
            arr[i] = arr[i - location];
        }
        //将临时数组里面元素放入原始数组最前面
        for (int i = 0; i < newArr.length; i++) {
            arr[i] = newArr[i];
        }
        System.out.println(Arrays.toString(arr));
    }
}
